function basePath() {
	// 获取当前网址，如： http://localhost:8080/ems/Pages/Basic/Person.jsp
	var curWwwPath = window.document.location.href;
	// 获取主机地址之后的目录，如： /ems/Pages/Basic/Person.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	// 获取主机地址，如： http://localhost:8080
	var localhostPath = curWwwPath.substring(0, pos);
	// 获取带"/"的项目名，如：/ems
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	// 获取项目的basePath http://localhost:8080/ems/
	var basePath = localhostPath + projectName + "/";
	return basePath;
};
projectPath = basePath();

// 表单数据转换成json(去除空字符)
$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();

	$(this).find('tbody').find('[name]').each(
			function() {
				if ($(this).attr('no') == 'N')
					return true;

				if ($(this).val() != '') {
					if ($(this).attr('type') == 'checkbox') {
						if ($(this).is(':checked')) {
							o[$(this).attr('name')] = "1";
						} else {
							o[$(this).attr('name')] = "0";
						}
					} else if ($(this).attr('type') == 'radio') {
						var val = $(
								'input:radio[name="' + $(this).attr('name')
										+ '"]:checked').val();
						o[$(this).attr('name')] = val;
					} else {
						if (o[$(this).attr('name')]) {
							if (!o[$(this).attr('name')].push) {
								o[$(this).attr('name')] = [ o[$(this).attr(
										'name')] ];
							}
							o[$(this).attr('name')].push($(this).val() || '');
						} else {
							o[$(this).attr('name')] = $(this).val() || '';
						}
					}
				}
			});
	return o;
};

$.fn.serializeObject1 = function() {
	var o = {};
	var a = this.serializeArray();

	$(this).find('[name]').each(
			function() {
				if ($(this).val() != '') {
					if ($(this).attr('type') == 'checkbox') {
						if ($(this).is(':checked')) {
							o[$(this).attr('name')] = "1";
						} else {
							o[$(this).attr('name')] = "0";
						}
					} else if ($(this).attr('type') == 'radio') {
						var val = $(
								'input:radio[name="' + $(this).attr('name')
										+ '"]:checked').val();
						o[$(this).attr('name')] = val;
					} else {
						if (o[$(this).attr('name')]) {
							if (!o[$(this).attr('name')].push) {
								o[$(this).attr('name')] = [ o[$(this).attr(
										'name')] ];
							}
							o[$(this).attr('name')].push($(this).val() || '');
						} else {
							o[$(this).attr('name')] = $(this).val() || '';
						}
					}
				}
			});
	return o;
};
$.fn.serializeObjectArray = function() {
	var a = [];
	$(this).find('tbody').find('tr').each(function() {
		var o = {};
		$(this).find('[name]').each(function() {
			if ($(this).val() != '') {
				o[$(this).attr('name')] = $(this).val();
			}

			if ($(this).attr('type') == 'checkbox') {
				if ($(this).is(':checked')) {
					o[$(this).attr('name')] = "1";
				} else {
					o[$(this).attr('name')] = "0";
				}
			}
		})
		if (!jQuery.isEmptyObject(o)) {
			a.push(o);
		}
	});

	return a;
}

// 获取url中的参数
function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg); // 匹配目标参数
	if (r != null)
		return decodeURI(r[2]);
	return null; // 返回参数值
}

// 获取url中的参数
function getUrlParamDecode(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
	var r = decodeURIComponent(window.location.search.substr(1)).match(reg); // 匹配目标参数
	if (r != null)
		return r[2];
	return null; // 返回参数值
}

// 定义页面的modal大小
function setModalSize() {
	var documentW = $(window).width();
	var documentH = $(window).height();
	$('#modalW').width(documentW * 0.7);
	$('#modalH').height(documentH * 0.7);
}

// 获取modal高度
function getModalHeight() {
	return $('#modalH').height();
}

function formatDate(date, format) {
	if (!date) {
		return '';
	} else if (typeof (date) == "string") {
		if ("null" == date) {
			return '';
		}
		return date;
	} else if (typeof (date) == "undefined" || "undefined" == date) {
		return '';
	} else if (typeof (date) == "object") {
		var year = date.year + 1900;
		var month = (date.month + 1) >= 10 ? (date.month + 1) : "0"
				+ (date.month + 1);
		var day = date.date >= 10 ? date.date : "0" + date.date;
		var hours = date.hours >= 10 ? date.hours : "0" + date.hours;
		var minutes = date.minutes >= 10 ? date.minutes : "0" + date.minutes;
		var seconds = date.seconds >= 10 ? date.seconds : "0" + date.seconds;
		if (format && "hh:mi:ss" == format) {
			return hours + ":" + minutes + ":" + seconds
		} else if (format && "yyyy-mm-dd" == format) {
			return year + "-" + month + "-" + day
		} else if (format && "yyyy年mm月dd日" == format) {
			return year + "年" + month + "月" + day + "日"
		} else if (format && "yyyy-mm-dd hh:mi:ss" == format) {
			return year + "-" + month + "-" + day + " " + hours + ":" + minutes
					+ ":" + seconds
		} else if (format && "yyyy-mm-dd hh:mi" == format) {
			return year + "-" + month + "-" + day + " " + hours + ":" + minutes
		} else if (format && "yyyy/mm/dd" == format) {
			return year + "/" + month + "/" + day
		} else if (format && "yyyy/mm/dd hh:mi:ss" == format) {
			return year + "/" + month + "/" + day + " " + hours + ":" + minutes
					+ ":" + seconds
		} else if (format && "yyyy/mm/dd hh:mi" == format) {
			return year + "/" + month + "/" + day + " " + hours + ":" + minutes
		}
		return year + "-" + month + "-" + day + " " + hours + ":" + minutes
				+ ":" + seconds;
	}
	return date;
}

Date.prototype.format = function(format) {
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	}
	if (/(y+)/.test(format))
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	for ( var k in o)
		if (new RegExp("(" + k + ")").test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
	return format;
}

function showShipInfo(jsonShip){
	for(var j in jsonShip){
		if($('[name="' + j + '"]').length > 0){
			$('[name="' + j + '"]').val(jsonShip[j]);
		}
	}
	$('#modalShip').modal('show');
}